package main

import (
	"fmt"
	"time"
)

type MyError struct {
	When time.Time
	What string
}

/**
实现了
type error interface {
    Error() string
}
*/
func (e *MyError) Error() string { //MARK 这是实现error的方法 打印会调用这里, 打印比String() 优先级高
	return fmt.Sprintf("error at %v, %s",
		e.When, e.What)
}
func (e *MyError) String() string {
	return fmt.Sprintf("正常 at %v, %s",
		e.When, e.What)
}

func run() error {
	return &MyError{
		time.Now(),
		"it didn't work",
	}
}

func main() {
	if err := run(); err != nil {
		fmt.Println(err)
	}
}
